﻿<Window x:Class="WPF_Mysteries.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WPF_Mysteries"
    WindowStartupLocation="CenterScreen"     
    WindowState="Maximized"
    Title="WPF_Mysteries" >


    <Window.Resources>
        <!-- Create a Person object -->
        <local:Person x:Key="person1" FirstName="sacha" LastName="barber"/>
        <local:Person x:Key="person2" FirstName="fred" LastName="durst"/>
    </Window.Resources>



    <ScrollViewer>
        
        <StackPanel Orientation="Vertical">
                
            <!-- Collection Content Weirdness -->
            <StackPanel Orientation="Vertical">
                <Label Content="Collection Content Weirdness" FontWeight="Bold"/>
                <Border CornerRadius="5" BorderThickness="2" BorderBrush="Black" 
                        Margin="10" Height="120" Background="LightGray">

                    <!-- Here is our ContentTestControl -->
                    <local:ContentTestControl x:Name="testControl">
                        <StackPanel Orientation="Vertical">
                            <Label>one</Label>
                            <Label>two</Label>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <Label>3</Label>
                            <Label>4</Label>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <Label>5</Label>
                            <Label>6</Label>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <Label>7</Label>
                            <Label>8</Label>
                        </StackPanel>
                    </local:ContentTestControl>

                </Border>
            </StackPanel>

            <!-- Creating Styles/Templates In Code -->
            <StackPanel Orientation="Vertical">

                <Label Content="Creating Styles/Templates In Code" FontWeight="Bold"/>
                <Border CornerRadius="5" BorderThickness="2" BorderBrush="Black" 
                        Margin="10" Height="Auto" Background="LightCyan">

                    <StackPanel Orientation="Vertical">

                        <!-- LISTBOX 1-->
                        <Label Content="My Style And DataTemplate Are done in XAML" Margin="0"/>
                        <!-- Style / Template, works fine in XAML -->
                        <ListBox x:Name="lstbox1" Background="White"
                                 Foreground="Black"
                                 ItemsSource="{Binding Path=GetPeople}" 
                                 Focusable="True" >
    
                            <ListBox.Resources>
                                <!-- Lets have a DataTemplate for a Person-->
                                <DataTemplate DataType="{x:Type local:Person}">

                                    <StackPanel Orientation="Horizontal" Margin="10">
                                        <Path Name="pathSelected" Fill="Orange" Stretch="Fill" Stroke="Orange" Width="15" 
                                            Height="20" Data="M0,0 L 0,10 L 5,5" 
                                            Visibility="Hidden"/>

                                        <StackPanel Orientation="Horizontal">
                                            <Label Content="{Binding FirstName}" Foreground="Black"/>
                                            <Ellipse Fill="Black" Height="5" Width="5" 
                                                     HorizontalAlignment="Center" 
                                                     VerticalAlignment="Center"/>
                                            <Label Content="{Binding LastName}" Foreground="Black"/>
                                            <ListBox>
                                                <ListBox.ItemsSource>
                                                    <Binding>
                                                        <Binding.Path>Cars</Binding.Path>
                                                    </Binding>
                                                </ListBox.ItemsSource>
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <Label Content="{Binding Brand}"/>
                                                    </DataTemplate>                                                    
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                        
                                    </StackPanel>
                                    
                                    <DataTemplate.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                                AncestorType={x:Type ListBoxItem}, AncestorLevel=1}, Path=IsSelected}" Value="True">
                                            <Setter TargetName="pathSelected" Property="Visibility" Value="Visible"  />
                                        </DataTrigger>
                                    </DataTemplate.Triggers>
                                    
                                </DataTemplate>
                            </ListBox.Resources>
                            
                            <ListBox.ItemContainerStyle>
                                <!-- And how about a nice simple Style for a ListBoxItem -->
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="TextElement.FontSize" Value="14"/>

                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="true">
                                            <Setter Property="Foreground" Value="Black" />
                                            <Setter Property="Background">

                                                <Setter.Value>

                                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">

                                                        <LinearGradientBrush.GradientStops>
                                                            <GradientStop Color="#0E4791" Offset="0"/>
                                                            <GradientStop Color="#468DE2" Offset="1"/>
                                                        </LinearGradientBrush.GradientStops>
                                                    </LinearGradientBrush>

                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="Cursor" Value="Hand"/>
                                        </Trigger>
                                    </Style.Triggers>

                                </Style>
                            </ListBox.ItemContainerStyle>
                            
                        </ListBox>


                        <!-- LISTBOX 2-->
                        <Label  Content="My Style And DataTemplate Are done in C#" Margin="0,10,0,0"/>
                        <Button x:Name="btnCreate" Content="Create DataTemplate &amp; Style In Code" Click="btnCreate_Click"/>
                        
                        <!-- Lets try and do another MultiBinding is C# -->
                        <ListBox x:Name="lstbox2" Background="White"
                                 Foreground="Black"
                                 ItemsSource="{Binding Path=GetPeople}" 
                                 Focusable="True" >
                        </ListBox>

                    </StackPanel>

                </Border>
            </StackPanel>

        </StackPanel>
    </ScrollViewer>
    
    
    
    
    
</Window>
